﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Xk
{
    public partial class frmCourse : Form
    {
        public frmCourse()
        {
            InitializeComponent();
        }

        private void courseBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.courseBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.dsXk);

        }

        private void frmCourse_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dsXk.Course”中。您可以根据需要移动或删除它。
            this.courseTableAdapter.Fill(this.dsXk.Course);

        }

        private void ChangeEnabledState()
        {
            courseBindingNavigator.Enabled = !courseBindingNavigator.Enabled;
            gbEdit.Enabled = !gbEdit.Enabled;
            foreach (ToolStripButton b in tsControl.Items)
            {
                b.Enabled = !b.Enabled;
            }
        }

        private void tsbInsert_Click(object sender, EventArgs e)
        {
            ChangeEnabledState();
            courseBindingSource.AddNew();
            couNoTextBox.Focus();
        }

        private void tsbEdit_Click(object sender, EventArgs e)
        {
            ChangeEnabledState();
            couNoTextBox.Focus();
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            ChangeEnabledState();
            this.Validate();
            this.courseBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.dsXk);
        }

        private void tsbCancel_Click(object sender, EventArgs e)
        {
            ChangeEnabledState();
            this.courseBindingSource.CancelEdit();
        }

        private void tsbDelete_Click(object sender, EventArgs e)
        {
            if (courseBindingSource.Current != null)
            {
                if (MessageBox.Show("确定要删除么？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    courseBindingSource.RemoveCurrent();
                    this.tableAdapterManager.UpdateAll(this.dsXk);
                }
            }
        }
    }
}
